< previous page page_399 next page >

Page 399
                End If
                BBEnable frmTemp, "11111111"
            Case 7 ' move last
                rs.MoveLast
                lngResult = RSInit(frmTemp)
                If lngResult = 0 Then
                    lngResult = RSRead(frmTemp)
                End If
                BBEnable frmTemp, "11111111"
    End Select
    '
    BBProcess = 0
    Exit Function
    '
LocalErr:
    BBProcess = Err.Number
    '
End Function
Note.gif
The routine in Listing 10.19 is the last library function you'll be adding. Be sure to save the updated library file to disk before exiting Visual Basic.

Several aspects of Listing 10.19 need review. First, because you are using a command button array, all operations are dependent on which button was pushed. The outer Select Case structure handles the action. The comment lines show what each button is labeled. However, the captions (and functions) of the first two buttons (Add and Edit) can change during the course of the data entry process. Therefore, these two options have an additional Select Case to check the caption status of the selected button.
There are a great number of If..End If blocks in the code. These blocks are present because you are constantly checking the results of previous actions. They clutter up the code a bit, but they provide solid error-checking capability and program flow control.
Each main section of the outer Select Case performs all the operations needed to complete a user action. For example, the very first set of operations in the routine is the completion of the save operation for an Add command. If you ignore the constant checks of the nResult variable, you see that the essence of this section of the code is as follows:
· Write the record to the dataset (RSWrite)
· Commit the changes (rs.Update)
· Initialize the form controls (RSInit)
· Read the current record into the form (RSRead)

 
< previous page page_399 next page >

If you like this book, buy it!